const app = getApp();
const apiUrl = app.appData.url;
const loadingTxt = '拼命加载中...';
const apicontentType = app.appData.contentType;

function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
//request 请求
wxRequest = function(url, params, method) {
  method = method ? method : 'GET';
  return new Promise(function(resolve, reject) {
    const token = wx.getStorageSync("token");
    wx.request({
      url: apiUrl + url,
      header: {
        'content-type': apicontentType,
        'Accept': apicontentType,
        'Authorization': 'Bearer ' + token
      },
      method: method,
      data: params,
      success: function(res) {
        resolve(res.data);
      }
    });
  });
}

//获取首页数据列表
getIndexList = function(that) {
  const token = wx.getStorageSync("token");
  wx.request({
    url: apiUrl + 'index',
    data: {
      id: id
    },
    method: 'GET',
    header: {
      'content-type': apicontentType,
      'Accept': apicontentType,
      'Authorization': 'Bearer ' + token
    },
    success: function (response) {
      // that.setData({
      //   listFollows: response.data.data,
      // });
      // wx.hideLoading();
      console.log(response.data);
    },
  });
}
module.exports = {
  formatTime: formatTime,
  wxRequest: wxRequest,
}